<?php
class Db_About
{
    public static function total($condition=false) {
        static $totals;
        $key = hash('crc32b', $condition);
        if(!isset($totals[$key]))
            $totals[$key] = DB::count('about', $condition, __FILE__ . ' line ' . __LINE__);
        return $totals[$key];
    }

    public static function getAbouts($limit='', $condition='')
    {
        static $abouts;
        $key = hash('crc32b', $condition.$limit);

        if(!isset($abouts[$key]))
        {
            if($condition)
            {
            	$condition = 'WHERE '.$condition;
            }

            $abouts[$key] =  DB::fetch_all("SELECT * FROM about $condition $limit", __FILE__ . ' line ' . __LINE__);
        }

        return $abouts[$key];
    }




    public static function getAboutsId($limit='', $condition='', $indexId = true){
        static $abouts;
        $key = hash('crc32b', $condition.$limit);

        if(!isset($abouts[$key]))
        {
            if($condition)
            {
                $condition = 'WHERE '.$condition;
            }
            if($indexId){
                $abouts[$key] =  DB::fetch_all("SELECT id FROM about $condition $limit", __FILE__ . ' line ' . __LINE__);
            }else{
                $data =  DB::fetch_all_array("SELECT id FROM about $condition $limit", __FILE__ . ' line ' . __LINE__);
                $arrId = array();
                if($data !== null){
                    foreach($data as $t){
                        $arrId[]=$t['id'];
                    }
                }
                return $arrId;
            }

        }

        return $abouts[$key];
    }

    public static function selectAbouts($cols='*', $limit='', $condition='') {
        static $abouts;
        $key = hash('crc32b', $cols.$condition.$limit);
        if(!isset($abouts[$key])) {
            if($condition) $condition = 'WHERE '.$condition;
            $abouts[$key] =  DB::fetch_all("SELECT $cols FROM about $condition $limit", __FILE__ . ' line ' . __LINE__);
        }
        return $abouts[$key];
    }

    public static function getAboutById($id)
    {
        static $abouts;

        if(!isset($abouts[$id]))
        {
            $arrId = explode(',',$id);
            if(sizeof($arrId) >1){
                $abouts[$id] = DB::select('about', 'id IN ('.$id.')', __FILE__ . ' line ' . __LINE__);
            }else{
                $abouts[$id] = DB::select('about', 'id='.$id, __FILE__ . ' line ' . __LINE__);
            }

        }

        return $abouts[$id];
    }


    public static function insert($chief) {
        //var_dump($hotel);die;
        $id = DB::insert('about', $chief, false, __FILE__ . ' line ' . __LINE__);
        return $id;
    }

    public static function update($chief, $id)
    {

        return DB::update_id('about', $chief, $id, __FILE__ . ' line ' . __LINE__);
    }

    public static function updateStatusMenuById($id,$status)
    {
        return DB::update_id('chief', array("status" =>$status), $id, __FILE__ . ' line ' . __LINE__);
    }


    public static function delMenu($id)
    {
        return DB::delete_id('chief', $id, $id, __FILE__ . ' line ' . __LINE__);
    }



    public static function have_permit($pids, $id=false) {
        if(User::is_admin() || User::is_root()) return true;
        return false;
    }





}
